import BaseUserInfo from './baseUserInfo.js'
import LocalCacheMgr from './localCache.js'

export default class UserMgr {
	
	static shareInstance() {
		if(!this.s_instance) {
			this.s_instance = new UserMgr();
		}
		return this.s_instance;
	}
	
	static destoryInstance() {
		this.s_instance = null;
	}
	
	constructor() {
		this.currentUserInfo = new BaseUserInfo(LocalCacheMgr.shareInstance().getLoginUserInfo());
	}
	
	//当前登录用户信息
	getCurrentLoginUser() {
		return this.currentUserInfo;
	}
	
	//更新当前登录用户信息
	updateCurrentUserInfo(userinfo) {
		if(userinfo instanceof BaseUserInfo) {
			this.currentUserInfo = userinfo;
			LocalCacheMgr.shareInstance().setLoginUserInfo(userinfo);
		}
	}
	
	clearUserCache() {
	//清空缓存
		LocalCacheMgr.shareInstance().clearCache();
	}
}

UserMgr.s_instance = null;

